import TraceDisplay
from TraceDisplay import BOKEH_RENDERER
from IPython.display import HTML, display
import pandas as pd
pd.set_option('max_colwidth', 999)
image_path = ! find ${WALK_PATH:-.} -name '*.i.h5'
data_path = image_path[0]
html_path = '/dev/null'
data_path
image = TraceDisplay.Image()
image.load(data_path)
bkr = TraceDisplay.BokehRenderer()
bkr.show()
bkr.render(image)
# Create a snapshot before calling filter
# bkr.image
display(bkr)
display(image.filter)
display(image['/sched_switch'])
pid = image['/sched_process_exec'].iloc[0]['common_pid']
display(pid)
image.filter.update({
k:f"common_pid == {pid}"
for k in image
})
# Simulate Button click
bkr.update()
# Create a snapshot after calling filter
# bkr.image
display(bkr)
display(image.filter)
display(image['/sched_switch'])
# Append custom categories
image.category.append(
label=f'pid == {pid}',
color='#FF0000',
field='line0_category',
query = {
k:f"common_pid == {pid}"
for k in image
},
)
image.category.append(
label=f'pid != {pid}',
color='#00FF00',
field='line0_category',
query = {
k:f"common_pid != {pid}"
for k in image
},
)
nbcat = len(image.category)
image.filter.clear()
bkr.update()
display(bkr)
image.category
# Create two custom shapes
# Example: Task migration (as vertical lines between cpu) and Task running (as horizontal lines on cpu)
#
import numpy as np
display(image['/sched_migrate_task'])
image.shape.append({
'shape_class' : 'LineShape',
'shape_field' : {
'/sched_migrate_task':{
'x0':'timestamp',
'y0':'orig_cpu',
'x1':'timestamp',
'y1':'dest_cpu',
'category':'line1_category',
},
'/sched_switch':{
'x0':'timestamp',
'y0':'cpu',
'x1':'nxts_cpu',
'y1':'cpu',
'category':'line1_category',
},
}
})
# Before drawing we need to set some categories
# Let's create per_pid categories with random colors
import random
r = lambda: random.randint(0,255)
random_color = lambda : '#%02X%02X%02X' % (r(),r(),r())
PID = np.unique(np.concatenate(([
np.unique(image['/sched_migrate_task']['pid']),
np.unique(image['/sched_switch']['next_pid']),
])))
for pid in PID:
image.category.append(
label=f'pid[{pid}]',
color=random_color(),
field='line1_category',
query={
'/sched_migrate_task':f'pid=={pid}',
'/sched_switch':f'next_pid=={pid}'
},
)
# Disable the two previous categories
image.category.loc[[nbcat-2,nbcat-1],['active']] = False
# Disable previous shape
nbshape = len(image.shape)
image.shape.loc[0:nbshape-2,['active']] = False
# Draw
bkr.update()
display(bkr)
display(image.category)
display(image.shape)